package com.buddy.syn.block._05;

/**
 * 当一个线程访问object的synchronized(this) 同步代码块时，
 * 其他线程对object其他synchronized(this)访问将被阻塞，
 * 说明sunchronized使用的 对象监视器 是一个
 */
public class DoubleSynBlockOneService {

    public void methodA() {
        try {
            synchronized (this) {
                System.out.println("A Begin Time = " + System.currentTimeMillis());
                Thread.sleep(2000);
                System.out.println("A End Time = " + System.currentTimeMillis());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void methodB() {
        synchronized (this) {
            System.out.println("B Begin Time = " + System.currentTimeMillis());
            System.out.println("B End Time = " + System.currentTimeMillis());
        }
    }

}
